//
//  ProjectListContainerController.swift
//  QualityControlSystem
//
//  Created by Daniel Hu on 1/5/17.
//  Copyright © 2017 com.mask. All rights reserved.
//

import UIKit
import PageMenu

class ProjectListContainerController: UIViewController {
    
    // MARK: - Properties
    var controllers = [ProjectListController]()
    var pageMenu: CAPSPageMenu?
    
    // MARK: - ViewController lifecycle
    override func viewDidLoad() {
        super.viewDidLoad()
//        navigationItem.title = "质量监督管理系统"
        setupUserInterface()
    }
    
//    override func viewDidAppear(_ animated: Bool) {
//        super.viewDidAppear(animated)
//        navigationItem.title = "质量监督管理系统"
//    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        navigationItem.title = "质量监督管理系统"
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        navigationItem.title = ""
    }
//    override func viewDidDisappear(_ animated: Bool) {
//        super.viewDidDisappear(animated)
//        navigationItem.title = ""
//    }
    
    func setupUserInterface() {
        addControllers()
        
        let parameters: [CAPSPageMenuOption] = [
            .scrollMenuBackgroundColor(UIColor.white),
            .viewBackgroundColor(Color.bgGray),
            .selectionIndicatorColor(Color.bg),
            .selectedMenuItemLabelColor(Color.bg),
            .unselectedMenuItemLabelColor(Color.textGray),
            .menuItemFont(UIFont.systemFont(ofSize: 17.0)),
            .menuHeight(40.0),
            .menuItemWidth(Screen.width / 2),
            .menuItemSeparatorWidth(0),
            .menuMargin(0),
            .centerMenuItems(true),
            .enableHorizontalBounce(true)
        ]
        pageMenu = CAPSPageMenu(viewControllers: controllers, frame: CGRect(x: 0.0, y: 0.0, width: view.frame.width, height: view.frame.height - (tabBarController?.tabBar.frame.size.height)!), pageMenuOptions: parameters)
        view.addSubview(pageMenu!.view)
    }
    
    func addControllers() {
        let controller = ProjectListController(type: 0)
        controller.title = "在建项目"
        controller.parentNavigationController = self.navigationController
        controllers.append(controller)
        
        let controller1 = ProjectListController(type: 1)
        controller1.title = "待整改项目"
        controller1.parentNavigationController = self.navigationController
        controllers.append(controller1)
    }
}
